package yzx.firstletter.util;

import android.app.Activity;
import android.view.View;

import java.lang.reflect.Field;

public class Injector {

    public static void injectField(Activity activity){
        Field[] fields = activity.getClass().getDeclaredFields();
        for (Field f : fields) {
            f.setAccessible(true);
            ID id = f.getAnnotation(ID.class);
            if(id!=null && id.id()>0){
                View view = activity.findViewById(id.id());
                if(view != null)
                    try {
                        f.set(activity, view);
                    } catch (IllegalAccessException e) {
                    }
            }
        }
    }

}
